//
// Created by martin on 3/25/22.
//

#ifndef MUDUO_FTPRESPONSE_H
#define MUDUO_FTPRESPONSE_H

#include "muduo/base/copyable.h"
#include "muduo/net/Buffer.h"

namespace ftp
{

class FtpResponse : public muduo::copyable
{
public:
    enum FtpResponseCode
    {
        k0None = 0,
        k110RestartMarkerReply = 110,
        k120ServiceNotReady = 120,
        k125DataConnectionOpend = 125,
        k150FileOkay =  150,
        k200CommandOkay = 200,
        k202SuperfluousCommand = 202,
        k211SystemStatus = 211,
        k212DirectoryStatus = 212,
        k213FileStatus = 213,
        k214HelpMessage = 214,
        k215SystemType = 215,
        k220ServiceReady = 220,
        k221ServiceClose = 221,
        k225DataConnectionOpenNoTransfer = 225,
        k226ClosingDataConnection = 226,
        k227EnterPassiveMode = 227,
        k230UserLoggedIn = 230,
        k232AuthorizedSecurityDataExchange = 232,
        k250RequestedFileActionOkay = 250,
        k257PathnameCreated = 257,
        k331NeedPassword = 331,
        k332NeedAccount = 332,
        k350RequestedFileActionPending = 350,
        k421ServiceNotAvailable = 421,
        k425OpenDataConnectionFailure = 425,
        k426TransferAborted = 426,
        k450FileUnvailable = 450,
        k451LocalError = 451,
        k452RequestedActionNotTaken = 452,
        k500CommandUnrecognized = 500,
        k501ParamUnrecognized = 501,
        k502UnsupportedCommand = 502,
        k503BadSequence = 503,
        k504ParamNotImplement = 504,
        k530NotLoggedIn = 530,
        k534RequestDenied = 534,
        k535FailedSecurityCheck = 535,
        k536RequestedPROTLevelNotSupported = 536,
        k550RequestedActionNotTaken = 550,
        k551PageTypeUnknown = 551,
        k552ExceededStorageAllocation = 552,
        k553FileNameNotAllowed = 553,
    };

    FtpResponse()
    : code_(k0None),
    text_()
    { }

    bool invalid() const
    { return code_ == k0None; }

    void setMessage(const FtpResponseCode& code, const std::string& message)
    {
        setCode(code);
        setText(message);
    }

    void setCode(const FtpResponseCode& code)
    { code_ = code; }

    void setText(const std::string& text)
    { text_ = text; }

    void appendToBuffer(muduo::net::Buffer* output) const;

private:
    FtpResponseCode code_;
    std::string text_;
};

} // namespace ftp

#endif //MUDUO_FTPRESPONSE_H
